package dao.impl.jpa;

import java.util.List;

import javax.persistence.TemporalType;

import dao.PlanningDAO;
import domain.Planning;

public class PlanningDAOImpl extends BasePersistence implements PlanningDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<Planning> findByReis(int reis_id) {
        open();
        List<Planning> set = em.createNamedQuery("Planning.findByReisId").
        		setParameter("reis_id", reis_id).getResultList();
        close();
		return set;
	}

	@Override
	public Planning checkGidsBezet(Planning nieuwePlanning) {
		
		open();
		try {
			Planning planning = (Planning) em.createNamedQuery("Planning.checkGidsBezet").
					setParameter("planning_id", nieuwePlanning.getPlanningId()).
					setParameter("persoon_id", nieuwePlanning.getGids().getPersoonId()).
					setParameter("startdatum", nieuwePlanning.getStartdatum(), TemporalType.DATE).
					setParameter("einddatum", nieuwePlanning.getEinddatum(), TemporalType.DATE).getSingleResult();
			close();
			return planning;
		} catch (Throwable e) {
			return null;
		}
	}
}
